package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 查询当前登录用户的地址信息
     * @param addressBook
     * @return
     */
    public List<AddressBook> list(AddressBook addressBook);

    /**
     * 新增地址
     * @param addressBook
     * @return
     */
    int save(AddressBook addressBook);

    /**
     * 设置默认地址
     * @param addressBook
     * @return
     */
    int update(AddressBook addressBook);

    /**
     * 设置所有地址为非默认
     * @param addressBook
     * @return
     */
    int setDefaultByUserId(AddressBook addressBook);

    /**
     * 根据id删除地址
     * @param id
     * @return
     */
    @Delete("delete from address_book where id = #{id}")
    int deleteById(Long id);

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);
}
